﻿<%@ Page Culture="auto" UICulture="auto" Title="Identity constraints" Language="C#"
    MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="IdentityConstraint.aspx.cs"
    Inherits="BM.Tools.WebControls.MForm.Example.Constraints.IdentityConstraint" %>

<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls.Additions"
    TagPrefix="mfadd" %>
<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls"
    TagPrefix="mf" %>
<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls.Modifiers"
    TagPrefix="mfmod" %>
<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls.ValueHandlers"
    TagPrefix="mfvh" %>
<%@ Register TagPrefix="mftitle" Namespace="BM.Tools.WebControls.MForm.Controls.Titles"
    Assembly="BM.Tools.WebControls.MForm" %>
<asp:Content ContentPlaceHolderID="Demonstration" runat="server">
    <asp:XmlDataSource ID="XmlDataSource1" runat="server">
        <Data>            
            <Team>
                <Reference>
                    <MainPerson>3</MainPerson>
                </Reference>
                <Person key="1">
                    <FirstName>Edgar</FirstName>
                    <Surname>Polgar</Surname>
                </Person>
                <Person key="2">
                    <FirstName>Francis</FirstName>
                    <Surname>Drake</Surname>
                </Person>
                <Person key="3">
                    <FirstName>Marty</FirstName>
                    <Surname>Kalish</Surname>
                </Person>
                <Person key="4">
                    <FirstName>Debra</FirstName>
                    <Surname>Glatz</Surname>
                </Person>
                <Person key="5">
                    <FirstName>Jeff</FirstName>
                    <Surname>Lazarus</Surname>
                </Person>                
            </Team>          
        </Data>
    </asp:XmlDataSource>
    <p>
        Notice that the key value of the Person item cannot repeat.
    </p>
    <p>
        Also notice that when you add a person, remove a person or change the first or last
        name of a person, these values dynamically change in the Main Person field.
    </p>
    <mf:RootValidator runat="server" ControlToValidate="Root1" />
    <mf:Root ID="Root1" runat="server" DataSourceID="XmlDataSource1">
        <UriMappings>
            <mf:UriMapping Prefix="" Namespace=""></mf:UriMapping>
        </UriMappings>
        <Contents>
            <mf:Branch Name="Team" runat="server">
                <Contents>
                    <mf:Branch Name="Reference" runat="server">
                        <Contents>
                            <mf:Leaf Name="MainPerson" runat="server" DataType="PositiveInteger">
                            </mf:Leaf>
                        </Contents>
                    </mf:Branch>
                    <mf:Branch Name="Person" runat="server" MaxOccurs="10">
                        <Additions>
                            <mfadd:CombinedDescriptor runat="server">
                                <mfadd:ValueDescription Path="@key" />
                                <mfadd:TextDescription>) </mfadd:TextDescription>
                                <mfadd:ValueDescription Path="FirstName" />
                                <mfadd:TextDescription> </mfadd:TextDescription>
                                <mfadd:ValueDescription Path="Surname" />
                            </mfadd:CombinedDescriptor>
                        </Additions>
                        <Contents>
                            <mf:Leaf Name="key" runat="server" DataType="PositiveInteger" LeafType="Attribute">
                                <Additions>
                                    <mfadd:CombinedDescriptor runat="server">
                                        <mfadd:ValueDescription Path="../FirstName" />
                                        <mfadd:TextDescription> </mfadd:TextDescription>
                                        <mfadd:ValueDescription Path="../Surname" />
                                    </mfadd:CombinedDescriptor>
                                </Additions>
                            </mf:Leaf>
                            <mf:Leaf Name="FirstName" runat="server">
                                <Additions>
                                    <mfadd:Restriction runat="server" RestrictionType="MaxLength" Value="40"></mfadd:Restriction>
                                </Additions>
                            </mf:Leaf>
                            <mf:Leaf Name="Surname" runat="server">
                                <Additions>
                                    <mfadd:Restriction runat="server" RestrictionType="MaxLength" Value="40"></mfadd:Restriction>
                                </Additions>
                            </mf:Leaf>
                        </Contents>
                        <Modifiers>
                            <mfmod:SectionDisplayModifier HasMinimizing="true" />
                        </Modifiers>
                    </mf:Branch>
                </Contents>
                <Additions>
                    <mfadd:IdentityConstraint runat="server" AutoFill="True" Name="PersonKey" Selector="Person/@key">
                        <mfadd:KeyRef Selector="Reference/MainPerson"></mfadd:KeyRef>
                    </mfadd:IdentityConstraint>
                </Additions>
            </mf:Branch>
        </Contents>
    </mf:Root>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="Description" runat="server">
    <p>
        The identity constraints are a part of the xml schema specification.
    </p>
    <p>
        The identity constraints defined in xml schema will be ported to the generated MForm
        control.
    </p>
    <p>
        The identity constraints consist of two types: <code>keys</code> and <code>key references</code>.
    </p>
    <p>
        Both the <code>keys</code> and the <code>key references</code> work within the scope
        of the <code>IdentityConstaint</code> control.
    </p>
    <p>
        Items, that will have the <code>key</code> constraint are the ones, that are selected
        with the use of <code>Selector</code> property, relative to the <code>IdentityConstaint's</code>
        owner item.
    </p>
    <p>
        Items, that will have the <code>key reference</code> constraint are the ones, that
        are defined with the use of <code>KeyRef</code> inner property, selected with the
        use of its <code>Selector</code> property.
    </p>
    <div class="Section">
        <mftitle:TitleControl runat="server" Text="The keys" />
        <p>
            All items with the same key constraint, need to have unique values.
        </p>
        <p>
            In a situation, when the value of the key is unimportant (it serves only as an id),
            the <code>AutoFill</code> property of the IdentityConstraint may be set. This way,
            when a new key item is created, it will be filled with the next possible integer
            value.
        </p>
    </div>
    <div class="Section">
        <mftitle:TitleControl runat="server" Text="The key references" />
        <p>
            All items with the key reference constraint, may only have a value from the list
            of key values.
        </p>
        <p>
            To make it possible, the item with the key reference constraint should have a <code>
                ValueHandler</code> that implements the <code>IListControlValueHandler</code>
            property. In other words, the <code>ValueHandler</code> of the key reference item
            should accept a list of possible values.
        </p>
        <div class="Remark">
            <p>
                In case the <code>ValueHandler</code> of the key reference item is of different
                type, it will be overriden with a <code>DropDownListValueHandler</code></p>
        </div>
        <div class="Remark">
            <p>
                Currently only <code>ListBoxValueHandler</code> and <code>DropDownListValuehandler</code>
                will function properly for key reference item on keys adding and removing on client
                side.</p>
        </div>
    </div>
</asp:Content>
